Howdy! My name is Shannon and I study birds. More specifically, I study the habitat selection, reproduction and movement ecology of Northern Harriers (Circus hudsonius) in Suisun Marsh. “Wow, that sounds like a lot”, you might say. Indeed, it is. But what it really boils down to is filling knowledge gaps about harrier ecology to better inform their management and conservation That’s pretty much it in a nutshell.

Use the storms data (included in RStudio) to create a plotly graph of the relationship between wind and pressure, where the status of the storm is indicated by a color.

library(viridis)
library(tidyverse)
glimpse(storms)
## Observations: 10,010
## Variables: 13
## $ name        <chr> "Amy", "Amy", "Amy", "Amy", "Amy", "Amy", "Amy", "Am…
## $ year        <dbl> 1975, 1975, 1975, 1975, 1975, 1975, 1975, 1975, 1975…
## $ month       <dbl> 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7…
## $ day         <int> 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 29, 30, …
## $ hour        <dbl> 0, 6, 12, 18, 0, 6, 12, 18, 0, 6, 12, 18, 0, 6, 12, …
## $ lat         <dbl> 27.5, 28.5, 29.5, 30.5, 31.5, 32.4, 33.3, 34.0, 34.4…
## $ long        <dbl> -79.0, -79.0, -79.0, -79.0, -78.8, -78.7, -78.0, -77…
## $ status      <chr> "tropical depression", "tropical depression", "tropi…
## $ category    <ord> -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0,…
## $ wind        <int> 25, 25, 25, 25, 25, 25, 25, 30, 35, 40, 45, 50, 50, …
## $ pressure    <int> 1013, 1013, 1013, 1013, 1012, 1012, 1011, 1006, 1004…
## $ ts_diameter <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
## $ hu_diameter <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
storms <- storms 

library(plotly)

#ggplotly(ggplot(data = storms)+
  #geom_jitter(aes(x = as.factor(wind), y = pressure, fill = status), pch = 21, alpha = 0.05)+ 
  #scale_fill_viridis_c()+ 
  #theme_bw()+
  #labs(title = "Hurricane Pressure vs. Wind", subtitle = "by storm status", x = "Wind Speed"))## this code didn't work. Won't allow the discrete character type for status to serve as a continous variable for "fill"

#answer code
plotly::ggplotly(storms %>%  
  ggplot()+
  geom_point(aes(wind, pressure, color = status))
)

Create a table that identifies the mean wind, pressure, ts_diameter, hu_diameter of each status of storm (remember to remove NAs!). Use the package htmlTable. Round each mean to only two decimal places (Hint look up the function round)

table <- storms %>%
  drop_na(ts_diameter, hu_diameter) %>% 
  group_by(status) %>% 
  summarise(mean_wind = mean(wind), mean_pressure = mean(pressure), mean_ts = mean(ts_diameter), mean_hu = mean(hu_diameter))

table$mean_wind<- round(table$mean_wind, digits = 2)
table$mean_pressure <- round(table$mean_pressure, digits = 2)
table$mean_ts <- round(table$mean_ts, digits = 2)
table$mean_hu <- round(table$mean_hu, digits=2)

htmlTable::htmlTable(table)
status mean_wind mean_pressure mean_ts mean_hu
1 hurricane 87.15 966.35 288.11 72.96
2 tropical depression 28.21 1006.47 0 0
3 tropical storm 45.75 999.03 159.61 0.04

CHALLENGE Find the duration, in number of days, of every hurricane from 2010 and later, and then use one of the map functions from purrr to write a sentence saying “Hurricane X lasted Y days” for each of these storms. You can look for some help with these functions here and here.

duration <- storms %>% 
  filter(status == "hurricane", year >= 2010) %>% 
  group_by(name, year) %>% 
  summarise(num_days = diff(range(day)))
  
map2_chr(.x = duration$name, .y = duration$num_days, function(X,Y) paste("Hurricane", X, "lasted", Y, "days"))
##  [1] "Hurricane Alex lasted 29 days"    
##  [2] "Hurricane Arthur lasted 2 days"   
##  [3] "Hurricane Chris lasted 0 days"    
##  [4] "Hurricane Cristobal lasted 3 days"
##  [5] "Hurricane Danielle lasted 7 days" 
##  [6] "Hurricane Danny lasted 2 days"    
##  [7] "Hurricane Edouard lasted 4 days"  
##  [8] "Hurricane Ernesto lasted 1 days"  
##  [9] "Hurricane Fay lasted 0 days"      
## [10] "Hurricane Fred lasted 30 days"    
## [11] "Hurricane Gonzalo lasted 6 days"  
## [12] "Hurricane Gordon lasted 2 days"   
## [13] "Hurricane Humberto lasted 2 days" 
## [14] "Hurricane Igor lasted 9 days"     
## [15] "Hurricane Ingrid lasted 2 days"   
## [16] "Hurricane Isaac lasted 1 days"    
## [17] "Hurricane Joaquin lasted 29 days" 
## [18] "Hurricane Julia lasted 3 days"    
## [19] "Hurricane Karl lasted 1 days"     
## [20] "Hurricane Kate lasted 0 days"     
## [21] "Hurricane Katia lasted 9 days"    
## [22] "Hurricane Kirk lasted 30 days"    
## [23] "Hurricane Leslie lasted 6 days"   
## [24] "Hurricane Lisa lasted 1 days"     
## [25] "Hurricane Maria lasted 1 days"    
## [26] "Hurricane Michael lasted 5 days"  
## [27] "Hurricane Nadine lasted 29 days"  
## [28] "Hurricane Nate lasted 1 days"     
## [29] "Hurricane Ophelia lasted 29 days" 
## [30] "Hurricane Otto lasted 1 days"     
## [31] "Hurricane Paula lasted 2 days"    
## [32] "Hurricane Philippe lasted 4 days" 
## [33] "Hurricane Rafael lasted 2 days"   
## [34] "Hurricane Richard lasted 1 days"  
## [35] "Hurricane Rina lasted 3 days"     
## [36] "Hurricane Sandy lasted 5 days"    
## [37] "Hurricane Shary lasted 0 days"    
## [38] "Hurricane Tomas lasted 26 days"